package com.example.test.accountinfoa.controller;

import com.example.test.accountinfoa.pojo.AccountChangeEvent;
import com.example.test.accountinfoa.service.AccountInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;


/**
 * @author HanLiBin
 * @version V1.0
 */
@RestController
public class AccountInfoController {
    @Autowired
    private AccountInfoService accountInfoService;

    @GetMapping("/bank1/transfer/{amount}")
    public String  transfer(@PathVariable Double amount) {
        // 创建一个事务id
        String tx_no= UUID.randomUUID().toString();
        AccountChangeEvent accountChangeEvent=new AccountChangeEvent();
        accountChangeEvent.setAccountNo("1");
        accountChangeEvent.setAmount(amount);
        accountChangeEvent.setTxNo(tx_no);
        accountInfoService.sendupdateAccountBalance(accountChangeEvent);
        return "bank1-"+amount;
    }
}
//    CREATE TABLE `de_duplication` (
//        `tx_no` varchar(64) NOT NULL,
//        `create_time` datetime DEFAULT NULL,
//        PRIMARY KEY (`tx_no`)
//        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
